﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 生产工位
    /// </summary>
    public partial class WorkshoStation : BusEntity
    {
        /// <summary>
        /// 生产单元ID
        /// </summary>
        public string UnitId { set; get; }

        /// <summary>
        /// 生产工位编码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 生产工位名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 工位类型(CF_Enum.Code=StationType)
        /// </summary>
        public string Type { set; get; }
    }

    public partial class WorkshoStation : BusEntity
    {
        /// <summary>
        /// 所属生产单元
        /// </summary>
        public WorkshoUnit Unit { set; get; }     
        
        public virtual List<WorkshoStationSetting> Settings { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class WorkshoStationTypeConfig : BusEntityTypeConfig<WorkshoStation>, IEntityTypeConfiguration<WorkshoStation>
    {
        public override void Configure(EntityTypeBuilder<WorkshoStation> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Unit).WithMany(p => p.Stations).HasForeignKey(p => p.UnitId);
            //builder.HasOne(p => p.Process).WithMany(p => p.Stations).HasForeignKey(p => p.ProcessId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.UnitId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            //builder.Property(p => p.ProcessId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Type).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();

            //builder.Property(p => p.OrderAddress).HasMaxLength(200);
            //builder.Property(p => p.MeterAddress).HasMaxLength(200);
            //builder.Property(p => p.QuantityAddress).HasMaxLength(200);
            //builder.Property(p => p.StartUpAddress).HasMaxLength(200);
            //builder.Property(p => p.CompleteAddress).HasMaxLength(200);
            //builder.Property(p => p.EnabledAddress).HasMaxLength(200);
            #endregion

            #region 备注
            builder.HasComment("生产工位");
            builder.Property(p => p.UnitId).HasComment("生产单元ID");
            //builder.Property(p => p.ProcessId).HasComment("工序ID");
            builder.Property(p => p.Code).HasComment("生产工位编码");
            builder.Property(p => p.Name).HasComment("生产工位名称");
            builder.Property(p => p.Type).HasComment("工位类型(CF_Enum.Code=StationType)");

            //builder.Property(p => p.OrderAddress).HasComment("计划下发：订单地址");
            //builder.Property(p => p.MeterAddress).HasComment("计划下发：物料地址");
            //builder.Property(p => p.QuantityAddress).HasComment("计划下发：数量地址");
            //builder.Property(p => p.StartUpAddress).HasComment("开工信号地址");
            //builder.Property(p => p.CompleteAddress).HasComment("完工信号地址");
            //builder.Property(p => p.EnabledAddress).HasComment("工位是否启用信号地址");
            #endregion

            #region 种子数据
            
            builder.HasData(new WorkshoStation() { Id = "2022C91001001", Code = "2022C91001001", UnitId = "C91001001", Name = "叶片分拣工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91002001", Code = "2022C91002001", UnitId = "C91002001", Name = "拼板上料工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91002002", Code = "2022C91002002", UnitId = "C91002001", Name = "中筒上料工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91002003", Code = "2022C91002003", UnitId = "C91002002", Name = "1#卷圆工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91002004", Code = "2022C91002004", UnitId = "C91002002", Name = "2#卷圆工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91002005", Code = "2022C91002005", UnitId = "C91002002", Name = "3#卷圆工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91003001", Code = "2022C91003001", UnitId = "C91003001", Name = "纵缝焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91003002", Code = "2022C91003002", UnitId = "C91003002", Name = "封头压入工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91003003", Code = "2022C91003003", UnitId = "C91003003", Name = "工装压入工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91003004", Code = "2022C91003004", UnitId = "C91003003", Name = "1#后锥后段预装工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91003005", Code = "2022C91003005", UnitId = "C91003003", Name = "2#后锥后段预装工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91003006", Code = "2022C91003006", UnitId = "C91003003", Name = "3#后锥后段预装工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004001", Code = "2022C91004001", UnitId = "C91004001", Name = "1#立式组对工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004002", Code = "2022C91004002", UnitId = "C91004001", Name = "2#立式组对工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004003", Code = "2022C91004003", UnitId = "C91004002", Name = "1#内环缝焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004004", Code = "2022C91004004", UnitId = "C91004002", Name = "2#内环缝焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004005", Code = "2022C91004005", UnitId = "C91004003", Name = "1#叶片摆搭工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004006", Code = "2022C91004006", UnitId = "C91004003", Name = "2#叶片摆搭工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004007", Code = "2022C91004007", UnitId = "C91004003", Name = "3#叶片摆搭工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004008", Code = "2022C91004008", UnitId = "C91004003", Name = "4#叶片摆搭工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004009", Code = "2022C91004009", UnitId = "C91004003", Name = "5#叶片摆搭工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004010", Code = "2022C91004010", UnitId = "C91004004", Name = "1#叶片满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004011", Code = "2022C91004011", UnitId = "C91004004", Name = "2#叶片满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004012", Code = "2022C91004012", UnitId = "C91004004", Name = "3#叶片满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004013", Code = "2022C91004013", UnitId = "C91004004", Name = "4#叶片满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004014", Code = "2022C91004014", UnitId = "C91004005", Name = "1#筒体合模工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004015", Code = "2022C91004015", UnitId = "C91004005", Name = "2#筒体合模工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004016", Code = "2022C91004016", UnitId = "C91004006", Name = "1#合模满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004017", Code = "2022C91004017", UnitId = "C91004006", Name = "2#合模满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004018", Code = "2022C91004018", UnitId = "C91004006", Name = "3#合模满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004019", Code = "2022C91004019", UnitId = "C91004006", Name = "4#合模满焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004020", Code = "2022C91004020", UnitId = "C91004007", Name = "1#外环缝焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004021", Code = "2022C91004021", UnitId = "C91004007", Name = "2#外环缝焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004022", Code = "2022C91004022", UnitId = "C91004007", Name = "3#外环缝焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004023", Code = "2022C91004023", UnitId = "C91004007", Name = "4#外环缝焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C91004024", Code = "2022C91004024", UnitId = "C91004008", Name = "1#补焊及修磨工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004025", Code = "2022C91004025", UnitId = "C91004008", Name = "2#补焊及修磨工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "2022C91004026", Code = "2022C91004026", UnitId = "C91004008", Name = "3#补焊及修磨工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "2022C9100501", Code = "2022C9100501", UnitId = "C91005001", Name = "筒体下线工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
